package demo05;

/**
 * @author: WangPeng
 * @createTime: 2022/11/01 9:41
 * @description:
 * @version: v1.0
 */
public class TestSleep {
    public static void main(String[] args) {
        SleepDemo sleepDemo = new SleepDemo("线程A");
        sleepDemo.start();
    }
}
class SleepDemo extends Thread{
    public SleepDemo(String name){
        super(name);
    }
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            try {
                //当前线程获取到cpu后，执行到该处代码时，会休眠1秒。休眠过后会继续执行。
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"执行====="+i);
        }
    }
}
